'********************************
'********QUOTES SCRIPT PLUGIN**********
'This enables a basic quotes system.  Can be easily modified to suit your
'personal needs
'USAGE:
'   .addquote <quote>  - adds quote to text file
'   .quote - displays the next quote(sequentially, starting at a random place)
'   .ranquote - returns a random quote from the file
'   .quoteidle <time> - uses the timer to display quotes on an idle time.
'               TIME is number of minutes, set to 0 to disable.
'               NOTE:  Timer CAN interfere with other scripts.


Dim FileSystemOb
Const ForRead = 1, ForWrite = 2, ForAppend = 8
Dim curSpot
Dim QuoteIdle
dim IdleMins
dim CurrentMin
Const ScriptVer="Quotes V1.0 by The-FooL"


'************
'//This Sub Is called When the script File is loaded
'**********
Sub Event_Load()
Set FileSystemOb = CreateObject("Scripting.FileSystemObject")
	ssc.AddChat vbgreen, "[Script]Quotes Script Loaded!"
	curSpot=-1
	quoteIdle=False
	scriptTimer.Interval=60000
	scriptTimer.Enabled=True
	IdleMins=10
randomize
End Sub



'************
'//Bot has logged onto Battle.net  SCGateway is the
'    SCGateway - "useast", "uswest", "asia", etc
'    WCGateway - "Azeroth", "Northrend", etc.
'    Both of the above are passed regardless of product
'****************
Sub Event_LoggedOn(Username, Product, SCGateway, WCGateway)

End Sub


Sub Event_Usertalk(Username, Flags, Message, Ping)


End Sub


'///My semi-Complex On Join Sub
'    Parsed Statstring - Contains the parsed statstring of the user
'    OrigStatString - Contains the unmodifed statstring of the user
'    Clan - WC Clan(If applicable)
'    GreetUser -   If false, then that means the user has already been
'    marked as banned(ban has been sent to que).  You should take advantage
'    Of this to not waste time with the user.  
'    
' //This is a Function(Default return value is always false).  If you set the return
'  value to TRUE ( Event_UserJoins=TRUE) then the greetUser variable will be set
'  to false(bot greets will not be sent, and user will not be checked for 
'  mail/lastseen).
' //Because I have already retrieved Access and Safelisted status, I have passed those
'    as well
'    
'**************
Function Event_UserJoins(Username, Flags, ParsedStatString, OrigStatString, Product, Clan, Ping, Access, safeListed, GreetUser)


End Function


Sub Event_ServerInfo(Message) 


End Sub


Sub Event_ServerError(Message)

End Sub



Sub Event_UserEmote(Username, Flags, Message)

End Sub


Sub Event_WhisperFromUser(Username, Flags, Message)

End Sub


Sub Event_WhisperToUser(Username, Flags, Message)

End Sub


Sub Event_UserLeaves(Username, Flags)

End Sub

Sub Event_FlagUpdate(Username, NewFlags, Ping, Message)

End Sub

Sub Event_UserInChannel(Username, Flags, Message, Ping, Product, OrigStatString)

End Sub

Sub Event_ChannelJoin(ChannelName) ' Bot joins a different Channel
	
End Sub


Sub scTimer_Timer() ' fires when the timer goes off

'//Timer Settings can be modifed with the added ScriptTimer Object
'//ScriptTimer.Enabled=True, ScriptTimer.Interval=1000, etc
if not quoteidle then exit sub
currentmin=currentmin+1
if currentmin>=idlemins THEN
	currentmin=0
	ssc.addq "/me :.: " & getNextQuote
END IF
End Sub


'************
'//Fires when enter is pressed in the send box
'    ''This is a function.  By default the return value is false.
'      However, if you set the return value to TRUE(Event_PressedEnter=True)
'      Then the text will not be processed by the bot as normal
Function Event_PressedEnter(Text)
	if text="/bob" then Event_PressedEnter=True
End Function

'************
'//FooLOps Command Processor
'    I added a seperate sub for a command processor, called directly by my command 
'    processor.  This sub is called only after triggers have been parsed, and
'    multiple commands have been split.  The Ops Commands(Bans, unbans, or whatever I
'    have in my ops commands sub) have precedence over this.  If they are parsed, 
'    then this sub will never be called.
'
'///Here is how you parse/return the command.  "Command" contains the first word, 
'   the actual command(no trigger).  Rest is the rest of the command
'  (whatever follows, if anything).
'   Set the return value with Event_ParseCommand="Return Message"
'   If the return message is blank, then the bot will consider the command unparsed
'   and continue to search through the rest of the commands list
'   If the return message is a single space ' ', then the bot will consider the command
'   parsed but will not return anything to the que or bot window.
'   Any real return message will either be added directly to the que(you can use 
'   vbCrLfs for multiple lines), or send to the bot window(depending on where the
'   command was called from.
'   All script command processors are processed simultaneosly, so that they will not interfere with eachother.

' It is also important to note that in addition to this, Event_Usertalk or Event_WhisperFromUser can also be called.


Function Event_ParseCommand(Command, Rest, Username, Access, Inbot)
select case command
	case "scriptver"
	   if access<20 then exit function
	   event_parsecommand =ScriptVer
        case "aboutscript"
	If access<50 then exit function
	   Event_ParseCommand="Quotes: Enables Quote features to foolops"
	case "addquote","aq"
	If access<50 then exit function
	addquote rest
	event_parseCommand="Quote Added."
	case "quote","getquote","nextquote"
	if access<50 then exit function
	event_parsecommand=getNextQuote
	case "ranquote","rquote","ranq"
	if access<50 then exit function
	event_parsecommand=getRandomQuote
	case "quoteidle"
	if access<50 then exit function
	on error resume next
	idlemins=0
	idlemins=cint(rest)
	if idlemins<=0 then
		idlemins=0
		quoteidle=false
		currentmin=0
		event_parsecommand="Quote Idles Deactivated"
	else
		quoteidle=true
		event_parsecommand="Quote Idles Set to [" & idlemins & "] minutes"
	end if	
		

end select

End Function

'///When The Script File is Unloaded(Bot Close)
Sub Event_Close()
	
End Sub

Sub AddQuote(QUote)
Set Quotes = FileSystemOb.OpenTextFile("quotes.dat", 8, true, 0)
Quotes.Writeline Quote
ENd sub

Function getNextQuote()
Set CCFile = FileSystemOb.OpenTextfile("quotes.dat", ForRead, True,  0)
s=split(CCFile.ReadAll,vbNewLine)
if curSpot=-1 THEN
	curSpot=Int(rnd*ubound(s))
END IF
If curSpot>ubound(s)-1 then curSpot=0
getNextQuote=s(CurSpot)
curSpot=curSpot+1

End function

Function getRandomQuote()
Set CCFile = FileSystemOb.OpenTextfile("quotes.dat", ForRead, True,  0)
s=split(CCFile.ReadAll,vbNewLine)
	x=Int(rnd*ubound(s))
If x>ubound(s)-1 then x=ubound(s)-1
getRandomQuote=s(x)

End function
